<%@ page language="java" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
    <%@include file="../common/base.jsp"%>
	<meta charset="utf-8" />
	<meta name ="viewport" content ="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
	<meta http-equiv="expires" content="0">
	<title>等待接驾</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
	<style>
		.layui-layer{
			overflow: hidden;
		}
	</style>
</head>
<body>
    <div class="container-fluid">
    	<div class="divBox driver-info">
			<%@include file="driverHtml.jsp"%>
			<p class="tip" id="timeLu">
				司机正在路上，请做好上车准备
			</p>
    	</div>
		<%@include file="startEnd.jsp"%>
<div class="l-footer">
	<a class="cancelBox">
		<img src="${base}/images/cancel.png">
		<p class="text">取消订单</p>
	</a>
	<%@include file="footer.jsp"%>
</div>

    	<a id="clickCall"  style="display: none;"> <span></span></a>
    </div>
<div id="container" style="display: none;"></div>
</body>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<%--<script src="https://cdn.bootcss.com/crypto-js/3.1.9/crypto-js.min.js"></script>--%>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js?version=${version}"></script>
<%--<script type="text/javascript" src="${base}/plugin/jsencrypt/jsencrypt.min.js"></script>--%>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    var yun=new yueajax( "${openId}");
	var $document = $(document);
	//	取消订单
    $document.on('touchend', '.cancelBox', function(event){

        layer.confirm('司机已经在赶来接您的的路上了，请您在耐心等等吧', {
        	area: ['95%','auto'],
            title: "取消叫车",
            btn: ['联系师傅','确定取消'] //按钮
        }, function(index){
            $('#driver_mobile').find('img').click();
            layer.close(index);
        }, function(index){
            layer.close(index);
			changeUrl('cancelMsg',yun.orderUuid);
        });
    });
	//初始化请求订单数据
    getOrderStatus(function (data) {
		//订单创建时间
        var cTime=new Date(data.data.deparTime || data.data.createOn);
        var cTobj=yun.time_count(cTime)
        var driver=data.data.driver;
        $('#faceimg').attr('src',driver.face || '${base}/images/man.png');
        $('#driver_name').html(driver.name);
        $('#driver_score').append(driver.score)
        $('#driver_orderCount').html(driver.orderCount+'单')
        $('#driver_plateNum').html(driver.plateNum)
        $('#driver_carColor_brandName').html(driver.carColor+driver.brandName);
		$('#driver_mobile').attr('href','tel:'+driver.mobile);
		$('#clickCall').attr('href','tel:'+driver.mobile);

        $('#creadtime').html(cTobj.day+'  '+cTobj.hour+cTime.format('hh:mm'));
        $("#originDetailAddressText").html(data.data.originAddress);
        $("#destDetailAddressText").html(data.data.destAddress);
    });
	//定时请求OrderDetail，获取订单详情
	var interval=setInterval(getOrderStatus,5000);
	//获取刚才派出的订单ID
	function getOrderStatus(callback) {
        yun.order_ajax(function(data){

            var d=data.data;
            if (d.subStatus == 210 || d.subStatus == 200) {}else{
                changeUrl(data.data.subStatus,yun.orderUuid);
			}
            if(typeof callback =="function"){callback(data);}
            if(d.subStatus == 200 && d.typeTime==2 && !url.getQueryString('status') ){
                var tc=new Date(d.deparTime)
				var td=yun.time_count(tc);
                clearInterval(interval)
                $('#timeLu').html(td.day+"  "+td.hour+tc.format('hh:mm')+'出发，请做好准备');
                var isF=url.getQueryString('flag');
                if(isF!='false'){
//                    changeUrl(d.substatus,d.uuid+'&flag=false');
//                    setTimeout(function () {
//                        changeUrl('index')
//                    },5000)
                }

			}
            if(d.subStatus == 210){
                //乘客和司机距离，时间，路程计算亲求
                yun.twoPoint_ajax({
                    drivingType:'startDriving'
                },function(data){
                    var lu=(Math.round(data.data.distance/100))/10,duration=Math.round(data.data.duration/60);
                    if(lu<=0.1){
                        $('#timeLu').html('司机即将到达');
                    }else{
                        $('#timeLu').html('司机距您还有'+lu+'公里，预计'+duration+'分钟到达。');
                    }
                },function(data){
                    $('#timeLu').html(data.msg);
                })
			}

        },function (data) {layer.msg(data.msg())})
	}
});
</script>
</html>